package com.qububu.emporium.search.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qububu.emporium.goods.dto.GoodsInfoDto;
import com.qububu.emporium.search.dto.HotSearchWordDto;
import com.qububu.emporium.search.service.SearchService;
import com.qububu.utils.ParamConverter;
import com.qububu.utils.SystemConstants;

/**
 * @功能 关键字查询
 * 
 * @详情 参考文档
 * */
@Controller
@RequestMapping("/keySearch")
public class SearchControl {

	@Resource
	private SearchService searchService;
	
	/**
	 * @author HQ
	 * 
	 * @功能 热词查询，不用传递参数
	 */
	@RequestMapping("/ajaxHotSearch")
	@ResponseBody
	public Map<String, Object> searchHotInfo(HttpServletRequest request, HttpServletResponse response){
		
		Map<String, Object> hotMap = new HashMap<String, Object>();		
		List<HotSearchWordDto> hotWordList = searchService.getSearchInfoByHotWord();

		hotMap.put("result", SystemConstants.AJAX_SUCCESS);
		hotMap.put("hotWords", hotWordList);
		
		return hotMap;
	}
	
	/**
	 * @author HQ
	 * @功能 关键字查找
	 */
	@RequestMapping("/ajaxKeySearch")
	@ResponseBody
	public Map<String, Object> searchKeyInfo(HttpServletRequest request, HttpServletResponse response){
		
		Map<String, Object> keyMap = new HashMap<String, Object>();
		
		String keyWord = ParamConverter.assertNotEmpty(request.getParameter("keyWord"));
		List<GoodsInfoDto> keyWordList = searchService.getSearchInfoByKeyWord(keyWord);

		keyMap.put("result", SystemConstants.AJAX_SUCCESS);
		keyMap.put("keyWords", keyWordList);
		
		return keyMap;
	}
}
